package mest.service.hws.impl;

import com.alibaba.fastjson.JSON;
import mest.dao.hws.BomDao;
import mest.entity.bom;
import mest.service.hws.BomhwsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional(rollbackFor=Exception.class)
public class BomhwsServiceImpl implements BomhwsService {

    @Resource
    private BomDao bomDao;

    @Override
    public int deleteByPrimaryKey(String theirDb,Integer id) {
        return bomDao.deleteByPrimaryKey(theirDb,id);
    }

    @Override
    public String insert(String theirDb,bom record) {
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            bomDao.insert(theirDb,record);
            map.put("code",0);
            map.put("msg","添加成功");

        } catch (Exception e) {
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                map.put("msg","编码重复");
                return JSON.toJSONString(map);
            }
            map.put("msg", "添加失败");
        }
        return JSON.toJSONString(map);
    }

    @Override
    public int insertSelective(String theirDb,bom record) {
        return bomDao.insertSelective(theirDb,record);
    }

    @Override
    public bom selectByPrimaryKey(String theirDb,Integer id) {
        return bomDao.selectByPrimaryKey(theirDb,id);
    }

    @Override
    public int updateByPrimaryKeySelective(String theirDb,bom record) {
        return bomDao.updateByPrimaryKeySelective(theirDb,record);
    }

    @Override
    public int updateByPrimaryKey(String theirDb,bom record) {
        return bomDao.updateByPrimaryKey(theirDb,record);
    }

}
